import 'dart:convert';

import 'package:example_example/services/ScreenAdapter.dart';
import 'package:flutter/material.dart';
import '../../global/Global.dart';
import '../../global/GlobalUrl.dart';
import '../../services/TLSizeFit.dart';
import '../../util/LogUtil.dart';

import '../../YColors.dart';

//import '../pages/YColors.dart';
//import '../bean/order/MarketBean.dart';

Widget ItemToDoTaskView(context, bean, position, flag) {
  // TODO: implement build
  return Container(
    width: double.infinity,
//    margin: EdgeInsets.fromLTRB(20, 25, 20, 0),
//    padding: EdgeInsets.fromLTRB(10, 0, 10, 20),
    margin: EdgeInsets.fromLTRB(
        TLSizeFit.setPx(20), TLSizeFit.setPx(20), TLSizeFit.setPx(20), 0),
    padding: EdgeInsets.fromLTRB(TLSizeFit.setPx(20), TLSizeFit.setPx(4),
        TLSizeFit.setPx(20), TLSizeFit.setPx(20)),

    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        SizedBox(
          height: TLSizeFit.setPx(10),
        ),
        Row(
          children: <Widget>[
            Text(
//              bean["name"] != null ? bean["name"] : "",
              bean["processDefinitionName"] != null
                  ? bean["processDefinitionName"]
                  : "",
              style: TextStyle(
                fontSize: ScreenAdapter.size(34),
                color: YColors.a,
              ),
            ),
          ],
        ),
        SizedBox(
          height: TLSizeFit.setPx(14),
        ),

        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Text(
              "业务名称:",
              style: TextStyle(
                fontSize: ScreenAdapter.size(28),
                color: YColors.c,
              ),
            ),
            SizedBox(
              width: TLSizeFit.setPx(8),
            ),
//                Text(
//                  getBusinessName(bean),
//                  style: TextStyle(
//                    fontSize: ScreenAdapter.size(28),
//                    color: YColors.c,
//                  ),
//                ),
            Expanded(
                child: Container(
              child: Text(
                getBusinessName(bean),
                style: TextStyle(
                  fontSize: ScreenAdapter.size(28),
                  color: YColors.c,
                ),
              ),
            )),
          ],
        ),

        SizedBox(
          height: TLSizeFit.setPx(10),
        ),

        Row(
          children: <Widget>[
            Text(
              "开始时间:",
              style: TextStyle(
                fontSize: ScreenAdapter.size(28),
                color: YColors.c,
              ),
            ),
            SizedBox(
              width: TLSizeFit.setPx(8),
            ),
            Text(
              bean["createTime"] != null ? bean["createTime"] : "",
//              getDataStatusText(bean),
              style: TextStyle(
                fontSize: ScreenAdapter.size(28),
                color: YColors.c,
              ),
            ),
          ],
        ),

        SizedBox(
          height: TLSizeFit.setPx(10),
        ),

        Row(
          children: <Widget>[
            Text(
              "状态:",
              style: TextStyle(
                fontSize: ScreenAdapter.size(28),
                color: YColors.c,
              ),
            ),
            SizedBox(
              width: TLSizeFit.setPx(36),
            ),
            Text(
//              "状态。。。。。",
//              bean["status"]!=null? bean["status"]:"",
              getDataStatusText(bean),
              style: TextStyle(
                fontSize: ScreenAdapter.size(28),
                color: YColors.c,
              ),
            ),
          ],
        ),

        SizedBox(
          height: TLSizeFit.setPx(10),
        ),
//        InkWell(
//          child: Container(
//            padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
//            width: double.infinity,
////            color: YColors.l,
//            child: Row(
//              children: <Widget>[
//                Container(
//                  padding: EdgeInsets.fromLTRB(7, 4, 7, 4),
////                  color: YColors.m,
//                  child: Text(
//                    "查看流程图",
//                    style: TextStyle(
//                      fontSize: 14.0,
//                      color: YColors.a,
//                    ),
//                  ),
//
//                  decoration: BoxDecoration(
//                    color: YColors.m,
//                    borderRadius: BorderRadius.all(new Radius.circular(4)),
//                  ),
//                ),
//              ],
//            ),
//          ),
//          onTap: () {
//            print("查看流程图");
//            String processInstanceId = bean["processInstanceId"];
//            print("查看流程图processInstanceId:$processInstanceId");
//            if (processInstanceId == null) {
//              processInstanceId = "";
//            }
//            String url = GlobalUrl.WEB_CHART_URL +
//                "?processInstanceId=" +
//                processInstanceId +
//                "&platform=app";
//            Navigator.pushNamed(context, '/webViewUtilPage', //WebViewExample
//                arguments: {
//                  Global.WEBVIEW_TAG: Global.HIISTORYTASK,
//                  Global.WEBVIEW_URL: url,
//                }).then((value) {
//              print('webview:$value');
//            });
//          },
//        ),
      ],
    ),
//    Row(
//      mainAxisAlignment: MainAxisAlignment.start,
//      children: <Widget>[

//        (flag=="4")?
//        InkWell(
//          child: Image.asset(
//            (bean["selectFlag"]!=null&&bean["selectFlag"])
//                ? "images/skill_select.png"
//                : "images/skill_unselect.png",
//            width: 20,
//            height: 20,
//          ),
//          onTap: (){
//            print("选择了我了position:$position");
//
//          },
//        ):Container(),

//        Container(
//          margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
//        ),

//      ],
//    ),
    decoration: BoxDecoration(
        // 边框 zj
        color: YColors.t, // 背景色 zj
//        border: Border.all(
//          // 边框 zj
//            color: Colors.black12, // 边框颜色 zj
//            width: 1.0 // 边框宽度 zj
//
//        ),
        borderRadius: BorderRadius.all(// 圆角
            //  Radius.circular(150),    //圆形
            Radius.circular(4) // 圆角 zj
            ),
        boxShadow: [
          BoxShadow(
//                            color: Colors.black12,
//              color: Color(0x554CBC5A), // 55  是透明度
              color: Color(0x12000000), // 55  是透明度
              offset: Offset(0.0, 2.0), //阴影xy轴偏移量
              blurRadius: 4.0, //阴影模糊程度
              spreadRadius: 1 //阴影扩散程度
              )
        ]

//            // 设置单圆角：左上角的圆角为5，右上角的圆角为10
//            borderRadius: BorderRadius.only(
//                    topLeft: Radius.circular(5),
//                   topRight: Radius.circular(10),
//              ),

        ),
  );
}

/**
 * 项目名称
 * 业务名称
 */
String getBusinessName(bean) {
  // 多处调用
  var variableJson = bean['variableJson'];
//  LogUtil.v("variableJson:$variableJson");
  variableJson = json.decode(variableJson);
  var biProjectName = variableJson["title"]; //ppProjectName  biProjectName
  LogUtil.v("直接可以调用啊biProjectName:$biProjectName");
  if (biProjectName == null) {
    biProjectName = "";
  }
  return biProjectName;
}

/**
 * 状态
 */
String getDataStatusText(bean) {
  var variableJson = bean['variableJson'];
//  LogUtil.v("variableJson:$variableJson");
  variableJson = json.decode(variableJson);
  var statusText = variableJson["statusText"]; //statusText
//  LogUtil.v("statusText:$statusText");
  if (statusText == null) {
    statusText = "";
  }
  return statusText;
}
